<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-form-item>
          <el-input v-model="dataForm.keywords" placeholder="平台账号、名称" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="dataForm.identifier" placeholder="第三方唯一标识" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-select v-model="dataForm.identityType" placeholder="类型">
          <el-option key="" label="全部" value=""></el-option>
          <el-option :key="0" label="手机号" :value="0"></el-option>
          <el-option :key="1" label="邮箱" :value="1"></el-option>
          <el-option :key="2" label="用户名" :value="2"></el-option>
          <el-option :key="3" label="送贝用户端-微信号" :value="3"></el-option>
          <el-option :key="4" label="送贝商家端-微信号" :value="4"></el-option>
          <el-option :key="5" label="服务号-微信号" :value="5"></el-option>
          <el-option :key="6" label="送贝小程序-微信号" :value="6"></el-option>
          <el-option :key="7" label="支付宝提现专用" :value="7"></el-option>
          <el-option :key="8" label="QQ" :value="8"></el-option>
          <el-option :key="9" label="微博" :value="9"></el-option>
          <el-option :key="10" label="支付宝" :value="10"></el-option>
          </el-select>
      </el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <!-- <el-button v-if="isAuth('business:class:addClass')" type="primary" @click="addOrUpdateHandle()">新增</el-button> -->
        <!-- <el-button v-if="isAuth('class:shoppinguserclass:deleteByIds')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button> -->
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <!-- <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column> -->
      <el-table-column
        prop="userName"
        header-align="center"
        align="center"
        label="平台账号">
      </el-table-column>
      <el-table-column
        prop="nickName"
        header-align="center"
        align="center"
        label="第三方平台名称">
      </el-table-column>
      <el-table-column
        prop="identifier"
        header-align="center"
        align="center"
        label="唯一标识">
      </el-table-column>
      <el-table-column
        prop="identityType"
        header-align="center"
        align="center"
        label="类型">
        <template slot-scope="scope">
          <el-tag>{{scope.row.identityType === 0 ? '手机号' : (scope.row.identityType === 1 ? '邮箱' : (scope.row.identityType === 2 ? '用户名' : (scope.row.identityType === 3 ? '送贝用户端-微信号' : (
              scope.row.identityType === 4 ? '送贝商家端-微信号' : (scope.row.identityType === 5 ? '服务号-微信号' : (scope.row.identityType === 6 ? '送贝小程序-微信号' : (scope.row.identityType === 7 ? '支付宝提现专用' : (
                  scope.row.identityType === 8 ? 'QQ' : (scope.row.identityType === 9 ? '微博' : '支付宝')
              ))))))))}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        header-align="center"
        align="center"
        label="创建时间">
      </el-table-column>
      <!-- <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
          <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
//   import AddOrUpdate from './shoppinguserclass-add-or-update'
  export default {
    data () {
      return {
        dataForm: {
          keywords: '',
          identityType: '',
          identifier: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    // components: {
    //   AddOrUpdate
    // },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/auth/queryToGrantAuthorizationList'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'keywords': this.dataForm.keywords,
            'identifier': this.dataForm.identifier,
            'identityType': this.dataForm.identityType
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.data.list
            this.totalPage = data.data.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      }
      // 新增 / 修改
    //   addOrUpdateHandle (id) {
    //     this.addOrUpdateVisible = true
    //     this.$nextTick(() => {
    //       this.$refs.addOrUpdate.init(id)
    //     })
    //   }
    }
  }
</script>
